<?php
session_start();
if ($_SESSION['user'] == "") {
    ?>
    <script>
        alert('当前未登录！');
        window.location.href = '../login.php';
    </script>
    <?php
}?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查询会员信息</title>
    <link href="/css/index.css" rel="stylesheet" type="text/css" >
    <link href="/css/userQuery.css" rel="stylesheet" type="text/css" >
</head>
<body>
<div class="men">
    <div class="main_top">
        <?php include '../html/top.php'?>
    </div>
    <div class="main_center">
        <div class="main_center_left">
            <?php include '../html/left.php'?>
        </div>
        <div class="main_center_right">
            <form action="/action/searchUserAction.php" method="post">
                <div class="main">
                    <div class="center">
                        <div class="shousuo">
                            卡号：<input type="text" name="phone"><input type="submit" value="搜索">
                        </div>
                    </div>
                    <div class="right">
                        <ul class="biaoti">
                            <li>用户名</li>
                            <li>卡号</li>
                            <li>性别</li>
                            <li>身份证号码</li>
                            <li>状态</li>
                            <li>操作</li>
                        </ul>

                    <?php
                    //连接数据库
                    try {
                        $db = new PDO('mysql:dbname=books;host=127.0.0.1','root','123456');

                        $result= $db->prepare('select *from user where phone=:phone ');
                        $data[':phone']=$_POST['phone'];
                        $result->execute($data);
                        $re=$result->fetchAll();
                        if($re){
                            foreach($re as $list){?>
                                <ul class="shuju">
                                    <li><?="$list[name]"; ?></li>
                                    <li><?="$list[phone]"; ?></li>
                                    <li><?="$list[sex]"; ?></li>
                                    <li><?="$list[cardID]"; ?></li>
                                    <li>
                                        <?php
                                        if("$list[status]" ==1){
                                            echo "<span>未归还</span>";
                                        }else{
                                            echo "<span>已归还</span>";
                                        }
                                        ?>
                                    </li>
                                    <li>
                                        <a href="#">修改</a>
                                        <a href="#">删除</a>
                                    </li>
                                    <div style="clear: both;"></div>
                                </ul>
                                <?php
                            }
                        }else{
                            echo "<script> alert('查询失败!');</script>";

                        }
                    } catch (PDOException $e) {
                        echo 'Connection failed';
                    }
                    ?>
                    </div>
            </form>
        </div>
        <div style="clear: both;"></div>
    </div>
</div>

</body>
</html>